import * as api from '@/api/sale/customer/index';
import * as baseApi from '@/api/common/index';
export default {
  data() {
    return {
      filter: {
        options: {}
      },
      loading: false,
      customerId: null,
      detail: {},
      customerStatusOptions: [{
        id: 1,
        labelZhCh: '意向客户',
        labelEnUs: 'intentionalCustomer'
      },
      {
        id: 2,
        labelZhCh: '正式客户',
        labelEnUs: ' formalCustomer'
      }
      ],
      contactPositionOptions: [{
        id: '1',
        labelZhCh: '采购'
      },
      {
        id: '2',
        labelZhCh: '品质'
      },
      {
        id: '3',
        labelZhCh: '技术'
      },
      {
        id: '4',
        labelZhCh: '财务'
      },
      {
        id: '5',
        labelZhCh: '物流'
      }
      ],
      levelForm: [{
        label: 'sale.customer.rating',
        unit: '',
        element: 'select',
        name: 'rating',
        type: '',
        options: [{
          id: 1,
          labelZhCh: 'A+',
          labelEnUs: 'A+',
          value: 1
        },
        {
          id: 2,
          labelZhCh: 'A',
          labelEnUs: 'A',
          value: 2
        },
        {
          id: 3,
          labelZhCh: 'B',
          labelEnUs: 'B',
          value: 3
        },
        {
          id: 4,
          labelZhCh: 'C',
          labelEnUs: 'C',
          value: 4
        },
        {
          id: 5,
          labelZhCh: 'D',
          labelEnUs: 'D',
          value: 5
        }
        ],
        isRequired: false
      }],
      moreForm: [{
        label: 'sale.customer.brandInfluence',
        unit: '',
        element: 'select',
        name: 'brandInfluence',
        labelWidth: '180px',
        type: '',
        options: [{
          id: 1,
          labelZhCh: '大名鼎鼎',
          value: 1
        },
        {
          id: 2,
          labelZhCh: '崭露头角',
          value: 2
        },
        {
          id: 3,
          labelZhCh: '默默无闻',
          value: 3
        }
        ],
        isRequired: false
      },
      {
        label: 'sale.customer.marketPosition',
        unit: '',
        element: 'select',
        name: 'marketPosition',
        options: [{
          id: 1,
          labelZhCh: '引领市场',
          value: 1
        },
        {
          id: 2,
          labelZhCh: '跟随市场',
          value: 2
        }
        ],
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.competitor',
        unit: '',
        element: 'textarea',
        name: 'competitor',
        type: '',
        labelWidth: '180px',
        isRequired: false
      },
      {
        label: 'sale.customer.successFactor',
        unit: '',
        element: 'textarea',
        name: 'successFactor',
        labelWidth: '180px',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.valueProposition',
        unit: '',
        element: 'textarea',
        labelWidth: '180px',
        name: 'valueProposition',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.fiAnnualReport',
        unit: '',
        element: 'textarea',
        labelWidth: '180px',
        name: 'fiAnnualReport',
        type: '',
        hidden: true,
        isRequired: false
      },
      {
        label: 'sale.customer.mediaCoverage',
        unit: '',
        element: 'textarea',
        name: 'mediaCoverage',
        labelWidth: '180px',
        type: '',
        hidden: true,
        isRequired: false
      },
      {
        label: 'sale.customer.otherInfo',
        unit: '',
        element: 'textarea',
        labelWidth: '180px',
        name: 'otherInfo',
        type: '',
        isRequired: false
      }
      ],
      abilityForm: [{
        label: 'sale.customer.capacitySatisfied',
        unit: '',
        element: 'radio',
        options: [{
          labelZhCh: '是',
          labelEnUs: 'Y',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '否',
          labelEnUs: 'N',
          value: 0,
          id: 0
        }
        ],
        name: 'capacitySatisfied',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.capacityUnsatisfyReason',
        unit: '',
        element: 'textarea',
        name: 'capacityUnsatisfyReason',
        type: '',
        hidden: true,
        isRequired: false
      },
      {
        label: 'sale.customer.priceSatisfaction',
        unit: '',
        element: 'select',
        name: 'priceSatisfaction',
        type: '',
        options: [{
          labelZhCh: '非常满意',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '满意',
          labelEnUs: '',
          value: 2,
          id: 2
        },
        {
          labelZhCh: '一般',
          labelEnUs: '',
          value: 3,
          id: 3
        }
        ],
        isRequired: false
      },
      {
        label: 'sale.customer.qualityLevel',
        unit: '',
        element: 'select',
        name: 'qualityLevel',
        type: '',
        options: [{
          labelZhCh: '优质',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '普通',
          labelEnUs: '',
          value: 2,
          id: 2
        },
        {
          labelZhCh: '待改进',
          labelEnUs: '',
          value: 3,
          id: 3
        }
        ],
        isRequired: false
      },
      {
        label: 'sale.customer.designingAbility',
        unit: '',
        element: 'select',
        options: [{
          labelZhCh: '出众',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '主流',
          labelEnUs: '',
          value: 2,
          id: 2
        },
        {
          labelZhCh: '平庸',
          labelEnUs: '',
          value: 3,
          id: 3
        }
        ],
        name: 'designingAbility',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.bizDevelopHelp',
        unit: '',
        element: 'select',
        name: 'bizDevelopHelp',
        labelWidth: '180px',
        options: [{
          labelZhCh: '积极',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '一般',
          labelEnUs: '',
          value: 2,
          id: 2
        },
        {
          labelZhCh: '无帮助',
          labelEnUs: '',
          value: 3,
          id: 3
        }
        ],
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.advantageAndDisadvantages',
        unit: '',
        element: 'label-block',
        labelWidth: '230px',
        name: '',
        type: '',
        col: 100,
        isRequired: false
      },
      {
        label: 'sale.customer.advantage',
        unit: '',
        element: 'textarea',
        name: 'advantage',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.disadvantages',
        unit: '',
        element: 'textarea',
        name: 'disadvantages',
        type: '',
        isRequired: false
      }
      ],
      conditionForm: [{
        label: 'sale.customer.currency',
        unit: '',
        element: 'select',
        name: 'currencyDv',
        type: 'multiple',
        value: 'value',
        isRequired: true
      },
      {
        label: 'sale.customer.paymentTerms',
        unit: '',
        element: 'select',
        name: 'paymentTermsDv',
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.adjustPriceCondition',
        unit: '',
        element: 'select',
        name: 'adjustPriceConditionDv',
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.deferredPenaltyCondition',
        unit: '',
        element: 'select',
        name: 'deferredPenaltyConditionDv',
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.afterSalesPeriod',
        unit: '',
        element: 'input',
        name: 'afterSalesPeriod',
        type: 'number',
        append: '年',
        isRequired: true
      },
      {
        label: 'sale.customer.warrantyCondition',
        unit: '',
        element: 'input',
        name: 'warrantyCondition',
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.deliveryTimeReq',
        unit: '',
        element: 'input',
        name: 'deliveryTimeReq',
        append: '天',
        type: 'number',
        isRequired: true
      },
      {
        label: 'sale.customer.factoryInspectionReq',
        unit: '',
        element: 'select',
        name: 'factoryInspectionReqDv',
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.insured',
        unit: '',
        element: 'radio',
        defaultValue: 0,
        options: [{
          labelZhCh: '是',
          labelEnUs: 'Y',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '否',
          labelEnUs: 'N',
          value: 0,
          id: 0
        }
        ],
        name: 'insured',
        type: '',
        col: 100,
        isRequired: true
      },
      {
        label: 'sale.customer.insuredAmount',
        element: 'input',
        append: '元',
        type: 'number',
        name: 'insuredAmount',
        hidden: true
      },
      {
        label: 'sale.customer.hasCoopAgreement',
        unit: '',
        element: 'radio',
        defaultValue: 0,
        options: [{
          labelZhCh: '是',
          labelEnUs: 'Y',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '否',
          labelEnUs: 'N',
          value: 0,
          id: 0
        }
        ],
        name: 'hasCoopAgreement',
        type: '',
        col: 100,
        isRequired: true
      },
      {
        label: 'sale.customer.coopAgreementFile',
        element: 'uploadFile',
        multiple: false,
        name: 'coopAgreementFileId',
        fileName: 'coopAgreementFileName',
        fileUrl: 'coopAgreementFileUrl',
        col: 100,
        hidden: true
      },
      {
        label: '协议签订日期',
        unit: '',
        element: 'datePicker',
        name: 'agreementDate',
        type: 'data',
        hidden: true,
        isRequired: false
      },
      {
        label: '协议有效期',
        unit: '',
        element: 'datePicker',
        name: 'agreementPeriod',
        type: 'data',
        hidden: true,
        isRequired: false
      }
      ],
      businessForm: [{
        label: 'sale.customer.productType',
        unit: '',
        element: 'select',
        name: 'productType',
        type: '',
        options: [{
          labelZhCh: '电动工具',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '园林工具',
          labelEnUs: '',
          value: 2,
          id: 2
        },
        {
          labelZhCh: '农业工具  ',
          labelEnUs: '',
          value: 3,
          id: 3
        }
        ],
        isRequired: true
      },
      {
        label: 'sale.customer.purchaseRatio',
        unit: '',
        element: 'input',
        name: 'purchaseRatio',
        append: '%',
        type: 'number',
        labelWidth: '400px',
        col: 100,
        // col: 100,
        isRequired: true
      },
      {
        label: 'sale.customer.purchaseCost',
        unit: '',
        element: 'input',
        name: 'purchaseCost',
        type: '',
        append: '万元',
        labelWidth: '400px',
        col: 100,
        isRequired: true
      }
      ],
      basicForm_af: [{
        label: 'sale.customer.employeesNum',
        unit: '',
        element: 'select',
        name: 'employeesNumDv',
        isRequired: true
      },
      {
        label: 'sale.customer.contactStartDate',
        unit: '',
        element: 'datePicker',
        name: 'contactStartDate',
        type: 'month',
        format: 'yyyy-MM',
        isRequired: true
      },
      {
        label: 'sale.customer.contactEndDate',
        unit: '',
        element: 'datePicker',
        name: 'contactEndDate',
        type: 'date',
        hidden: true, // 客户后来删除
        isRequired: false
      },
      {
        label: 'sale.customer.background',
        unit: '',
        element: 'textarea',
        name: 'background',
        type: '',
        hidden: true, // 客户后来删除
        labelWidth: '200px',
        isRequired: false
      },
      {
        label: 'sale.customer.operatingSitesAssets',
        unit: '',
        element: 'textarea',
        name: 'operatingSitesAssets',
        labelWidth: '200px',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.orgStructure',
        unit: '',
        element: 'textarea',
        name: 'orgStructure',
        labelWidth: '200px',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.branchOffice',
        unit: '',
        element: 'textarea',
        name: 'branchOffice',
        labelWidth: '200px',
        type: '',
        isRequired: false
      },
      {
        label: 'sale.customer.otherInfo',
        unit: '',
        element: 'textarea',
        name: 'otherInfo',
        labelWidth: '200px',
        type: '',
        placeholder: '如付款信用，社会影响力等',
        isRequired: false
      },
      {
        label: 'sale.customer.businessLicenseFile',
        unit: '',
        element: 'uploadFileImage',
        name: 'customerBusinessLicenseFileId',
        fileName: 'customerBusinessLicenseFileName',
        fileUrl: 'customerBusinessLicenseFileUrl',
        type: '',
        col: 100,
        multiple: false,
        isRequired: false
      }, {
        label: 'sale.customer.taxCardFile',
        unit: '',
        element: 'uploadFileImage',
        name: 'taxCardFileId',
        fileName: 'taxCardFileName',
        fileUrl: 'taxCardFileUrl',
        type: '',
        col: 100,
        multiple: false,
        isRequired: false
      }
      ],
      basicForm_pre: [{
        label: 'sale.customer.name',
        unit: '',
        element: 'input',
        name: 'name',
        col: 100,
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.shortName',
        unit: '',
        element: 'input',
        name: 'shortName',
        col: 100,
        type: '',
        isRequired: true
      },
      {
        label: 'sale.customer.code',
        unit: '',
        element: 'input',
        name: 'code',
        type: '',
        isRequired: false
      },{
        label: 'sale.customer.brand',
        unit: '',
        element: 'input',
        name: 'brand',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.form',
        unit: '',
        element: 'select',
        name: 'formDv',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.companyAddress',
        unit: '',
        element: 'input',
        name: 'companyAddress',
        col: 100,
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.companyTel',
        unit: '',
        element: 'input',
        name: 'companyTel',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.companyFax',
        unit: '',
        element: 'input',
        name: 'companyFax',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.country',
        unit: '',
        element: 'select',
        name: 'countryDv',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.salesArea',
        unit: '',
        element: 'select',
        append: '',
        name: 'salesAreaArray',
        type: 'multiple',
        isRequired: true
      },{
        label: 'sale.customer.character',
        unit: '',
        element: 'select',
        name: 'character',
        type: '',
        options: [{
          labelZhCh: '买受人',
          labelEnUs: '',
          value: 1,
          id: 1
        },
        {
          labelZhCh: '办事处',
          labelEnUs: '',
          value: 2,
          id: 2
        }],
        isRequired: true
      },{
        label: 'sale.customer.jobNumber',
        unit: '',
        element: 'input',
        name: 'jobNumber',
        type: '',
        isRequired: true
      },{
        label: 'sale.customer.erpBiz',
        unit: '',
        element: 'input',
        name: 'erpBiz',
        type: 'disabled',
        isRequired: true
      },{
        label: 'sale.customer.department',
        unit: '',
        element: 'input',
        name: 'department',
        type: 'disabled',
        isRequired: true
      }
      ]
    };
  },
  computed: {

  },
  created() {
    this.detail = this.dataInit();
  },
  methods: {
    dataInit() {
      const data = {
        // 基本信息1
        pdsCustomer: {
          customerStatus: 2 // 客户状态(1=意向客户，2=正式客户) ,
        },
        // 联系人列表
        pdsCustomerContactsList: [],
        // 基本信息2
        pdsCustomerBasicInfo: {
          // customerBusinessLicenseFile: [],
          // taxCardFile: []
        },
        // 业务信息
        pdsCustomerBizInfo: {},
        // 主要产品列表
        pdsCustomerProductsList: [],
        // 深度了解客户
        pdsCustomerDepthInfo: {},
        // 我方满足客户的能力
        pdsCustomerOurAbility: {},
        // 条款
        pdsCustomerTerms: {
          currencyDv: []
        }
      }
      return JSON.parse(JSON.stringify(data))
    },
    getPdsCustomerDetail() {
      api.getPdsCustomerDetail({
        customerId: this.customerId
      }).then(res => {
        this.refreshCb(res);
      });
    },
    refreshCb(res) {
      if (res.code === 200) {
        const setBasicFormDisabled = () => {
          this.basicForm_pre.map(item => {
            if (item.name == 'code') {
              item.disabled = true
            } else {
              if (
                res.data.pdsCustomer.customerStatus === 2 &&
                res.data.pdsCustomer.status === 2
              ) {
                item.disabled = true;
              } else {
                item.disabled = false;
              }
            }
          });
        };
        setBasicFormDisabled();
        res.data.pdsCustomerBasicInfo = res.data.pdsCustomerBasicInfo || {};
        res.data.pdsCustomerBizInfo = res.data.pdsCustomerBizInfo || {};
        res.data.pdsCustomerBizInfo = res.data.pdsCustomerBizInfo || {};
        res.data.pdsCustomerDepthInfo = res.data.pdsCustomerDepthInfo || {};
        res.data.pdsCustomerOurAbility = res.data.pdsCustomerOurAbility || {};
        res.data.pdsCustomerTerms = res.data.pdsCustomerTerms || {};
        res.data.pdsCustomerTerms.currencyDv = res.data.pdsCustomerTerms.currencyDv ? res.data.pdsCustomerTerms.currencyDv.split(',') : []
        res.data.pdsCustomerProductsList =
          res.data.pdsCustomerProductsList || [];
        res.data.pdsCustomerContactsList =
          res.data.pdsCustomerContactsList || [];
        const setBasicInfoFile = name => {
          const file = res.data.pdsCustomerBasicInfo[name]
          if (file && file.id) {
            res.data.pdsCustomerBasicInfo[name + 'Id'] = file.id
            res.data.pdsCustomerBasicInfo[name + 'Name'] = file.fileName
            res.data.pdsCustomerBasicInfo[name + 'Url'] = file.fileUrl
          }
        }
        setBasicInfoFile('customerBusinessLicenseFile')
        setBasicInfoFile('taxCardFile')
        this.conditionForm.map(item => {
          if (item.name === 'insured' || item.name === 'hasCoopAgreement' || item.name === 'capacitySatisfied') {
            if (this.$refs.basicForm_terms && this.$refs.basicForm_terms.radioChange) {
              this.$refs.basicForm_terms.radioChange(item.name, null, res.data.pdsCustomerTerms[item.name])
            }
          }
        })
        this.detail = Object.assign({}, res.data);
        console.log('xczxczxc',this.detail)
      }
    },
    // 获取字典选项
    getDict() {
      const codes =
        'pds_customer_form,comm_currency,pds_customer_adjust,pds_customer_delay,pds_customer_payment,comm_country,pds_customer_insp,pds_customer_emp_num,pds_customer_job';
      baseApi.getTypesValue(codes).then(res => {
        this.$set(this.basicForm_pre[4], 'options', res.data.pds_customer_form);
        this.$set(this.conditionForm[0], 'options', res.data.comm_currency);
        this.$set(this.basicForm_pre[3], 'options', res.data.comm_country);
        this.$set(this.basicForm_af[0], 'options', res.data.pds_customer_emp_num)
        this.$set(this, 'contactPositionOptions', res.data.pds_customer_job)
        this.$set(
          this.conditionForm[1],
          'options',
          res.data.pds_customer_payment
        );
        this.$set(
          this.conditionForm[2],
          'options',
          res.data.pds_customer_adjust
        );
        this.$set(
          this.conditionForm[3],
          'options',
          res.data.pds_customer_delay
        );
        this.$set(
          this.conditionForm[7],
          'options',
          res.data.pds_customer_insp
        );
      });
    }
  }
}
